package org.example.thread.threadException.threadpool;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;

/**
 * @Auther:Liu
 * @Testname:App
 * @Date:2025/8/14 17:01
 */
public class App {



    public static void a(){
//        单线程池
        ExecutorService executor = Executors.newSingleThreadExecutor();
        DemoA d1 = new DemoA();
        DemoA d2 = new DemoA();
        DemoA d3 = new DemoA();
        DemoA d4 = new DemoA();
        executor.execute(d1);
        executor.execute(d2);
        executor.execute(d3);
        executor.execute(d4);
        executor.shutdown();
    }

    public static  void b(){
//        定长线程池
        ExecutorService executor = Executors.newFixedThreadPool(2);
        DemoA d1 = new DemoA();
        DemoA d2 = new DemoA();
        DemoA d3 = new DemoA();
        DemoA d4 = new DemoA();
        executor.execute(d1);
        executor.execute(d2);
        executor.execute(d3);
        executor.execute(d4);
        executor.shutdown();
    }


    public static void c(){
//        可变线程池
        ExecutorService executor = Executors.newCachedThreadPool();
        DemoA d1 = new DemoA();
        DemoA d2 = new DemoA();
        DemoA d3 = new DemoA();
        DemoA d4 = new DemoA();
        executor.execute(d1);
        executor.execute(d2);
        executor.execute(d3);
        executor.execute(d4);
        executor.shutdown();
    }

    public static void d(){
        ScheduledExecutorService executor = Executors.newScheduledThreadPool(2);
        DemoB b = new DemoB();
        executor.scheduleAtFixedRate(b,10,2, TimeUnit.SECONDS);
    }


    public static void main(String[] args) {
        d();
    }
}
